package cn.zmall.manager.controller;

import cn.zmall.common.pojo.Result;
import cn.zmall.common.utils.ResultUtil;
import cn.zmall.content.service.ContentService;
import com.alibaba.dubbo.config.annotation.Reference;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author BinBini
 * @Date 2021/1/5 13:48
 * @Version 1.0
 */
@RestController
@Api(value = "缓存管理")
public class RedisController {

    @Reference
    private ContentService contentService;

    @RequestMapping(value = "/redis/index/list", method = RequestMethod.GET)
    @ApiOperation(value = "获取首页缓存")
    public Result<Object> getIndexRedis() {
        String json = contentService.getIndexRedis();
        return new ResultUtil<Object>().setData(json);
    }

    @RequestMapping(value = "/redis/index/update", method = RequestMethod.GET)
    @ApiOperation(value = "同步首页缓存")
    public Result<Object> updateIndexRedis() {
        contentService.updateIndexRedis();
        return new ResultUtil<Object>().setData(null);
    }

    @RequestMapping(value = "/redis/recommend/list", method = RequestMethod.GET)
    @ApiOperation(value = "获取推荐板块缓存")
    public Result<Object> getRecommendRedis() {
        String json = contentService.getRecommendRedis();
        return new ResultUtil<Object>().setData(json);
    }

    @RequestMapping(value = "/redis/recommend/update", method = RequestMethod.GET)
    @ApiOperation(value = "同步推荐板块缓存")
    public Result<Object> updateRecommendRedis() {
        contentService.updateRecommendRedis();
        return new ResultUtil<Object>().setData(null);
    }
}
